<template>

  <div>
    <el-container style="height: 900px; border: 1px solid #0b8ba5">
      <el-aside width="200px" style="background-color: rgb(238, 241, 246)">
        <el-menu :default-openeds="['1', '3']">


          <el-submenu index="3">
            <template slot="title"><i class="el-icon-setting"></i>管理</template>

            <el-menu-item-group title="管理信息">
              <el-menu-item index="3-3">
                <router-link to="/household">住户管理</router-link>
              </el-menu-item>

            </el-menu-item-group>
            <el-submenu index="3-4">
              <template slot="title">员工管理</template>

              <el-menu-item index="3-4-1">
                <router-link to="/emp">员工信息管理</router-link>
              </el-menu-item>
              <el-menu-item index="3-4-2">
                <router-link to="/dept">员工部门管理</router-link>
              </el-menu-item>
            </el-submenu>
          </el-submenu>
        </el-menu>
      </el-aside>

      <el-container>
        <el-header
          style="text-align: left; font-size: 40px;color: #cbf1f5;background-image: linear-gradient(to right, #acb6e5 , #86fde8 );">
          <div> 智慧园区&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
            &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
            部门管理系统
          </div>


        </el-header>

        <el-main>

          <br>

          <el-button type="primary">添加部门信息</el-button>
          <br>          <br>


          <el-table
            :data="tableData"
            border
            style="width: 100%">

            <el-table-column
              prop="deptname"
              label="部门名称"
              width="180">
            </el-table-column>
            <el-table-column
              prop="deptInterview"

              label="部门简介"
              width="800">

            </el-table-column>
            <el-table-column
              prop="deptnumber"
              label="人数"
              width="100">

            </el-table-column>

            <el-table-column
              prop="use"
              label="管理"
              width="200">

              <template slot-scope="scope">
                <el-button

                  size="mini"
                  @click="dialogFormVisible = true"> 编辑
                </el-button>


                <!-- Form -->

                <el-dialog title="部门管理编辑" :visible.sync="dialogFormVisible">
                  <el-form :model="form">
                    <el-form-item label="部门名称" :label-width="formLabelWidth">
                      <el-input v-model="form.deptname" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="部门简介" :label-width="formLabelWidth">
                      <el-input v-model="form.deptInterview" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="部门人数" :label-width="formLabelWidth">
                      <el-input v-model="form.deptnumber" autocomplete="off"></el-input>
                    </el-form-item>

                  </el-form>
                  <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogFormVisible = false">取 消</el-button>
                    <el-button type="primary" @click="dialogFormVisible = false;handle()">确 定</el-button>
                  </div>
                </el-dialog>

                <el-button
                  size="mini"
                  type="danger"
                  @click="handleDelete(scope.row.deptid)">删除
                </el-button>
              </template>
            </el-table-column>


          </el-table>


        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import axios from 'axios';

export default {
  mounted() {

    axios.get("http://localhost:9000/dept/dept_get").then((result) => {
      this.tableData = result.data.data;
    })
  },

  data() {


    return {

      tableData: [],

      dialogTableVisible: false,
      dialogFormVisible: false,
      form: {
        deptname: '',
        deptInterview: '',
        deptnumber: '',

      },
      formLabelWidth: '80px'
    }

  },

  methods: {
    onSubmit: function () {
      alert('submit!');
    },
    handle() {
      form
      alert("编辑成功");
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
    handleEdit(index, row) {
      console.log(index, row);
    },

    handleDelete(id) {

      this.$confirm('此操作将永久删除该住户信息, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {

        axios.delete('http://localhost:9000/dept/deptDelete', {
            params: {
              id: id
            }
          }
        )
        this.$router.go(0);
        this.$message({
          type: 'success',
          message: '删除成功!'
        });

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });

    }
  }
}

</script>
<style>
. .el-header {
  background-color: #0b8ba5;
  color: #0b8ba5;
  line-height: 60px;
}

.el-aside {
  color: #333;
}
</style>
